﻿@using eLoan.Models;
@model RequestCloseLoanModel

@{
    ViewBag.Title = "Reequest Close Loan";
}

<div class="row wrapper border-bottom white-bg page-heading">
    <div class="col-lg-10">
        <h2>Request Close Loan</h2>
        <ol class="breadcrumb">
            <li>
                Workspace
            </li>
            <li class="active">
                <strong>Request Close Loan</strong>
            </li>
        </ol>
    </div>
    <div class="col-lg-2"></div>
</div>


<div class="wrapper wrapper-content animated fadeInRight">
    <div class="row">
        <div class="col-lg-12">
            <div class="ibox float-e-margins">
            @using (Html.BeginForm("SaveRequestCloseLoan", "Workspace", FormMethod.Post, new { id = "saveForm" }))
            {
                <fieldset>
                    <div class="ibox-title">
                        <div class="divSearch">
                            <table class="table-search">
                                <tr>
                                    <td class="tdFixed">
                                        <span>@Html.LabelFor(m => m.Branches)</span>
                                        @Html.DropDownListFor(m => m.SelectedBranchCode, Model.Branches, new { @id = "ddlBranches", @class = "text-box single-line", @width = "50%" })
                                    </td>
                                    <td class="tdFixed">
                                        <span>@Html.LabelFor(m => m.SearchText)</span>
                                        @Html.TextBoxFor(m => m.SearchText, new { @id = "txtSearchText", @class = "text-box single-line", @width = "50%" })
                                    </td>
                                    <td class="tdFixed">
                                        <button type="submit" id="btnSearch" class="btn btn-primary btnSearch" name="command" value="Refresh">Search</button>
                                    </td>
                                    <td class="tdAlignRight" style="vertical-align:bottom; padding-bottom: 6px">
                                        <a href="#" class="btn btn-primary" data-toggle="modal" data-target="#confirm-close">Request to close selected documents</a>
                                    </td>
                                </tr>
                            </table>
                        </div>
                    </div>
                    <div class="ibox-content">
                        
                            <table id="tbl" class="table table-bordered table-List">
                                <thead>
                                    <tr>
                                        <th>Document No</th>
                                        <th>Borrower</th>
                                        <th>Agent</th>
                                        <th>Receivable</th>
                                        <th>Total Payment</th>
                                        <th>Outstanding Balance</th>
                                        <th>Loan Status</th>
                                        <th>Remarks</th>
                                        <th style="text-align:center">@Html.CheckBox("chkCheckAll", false, new { @class = "checkAll", @onchange = "checkAll(this)" })</th>
                                    </tr>
                                </thead>
                                <tbody id="tableBody">
                                    @for (var i = 0; i < Model.CloseLoanItems.Count(); i++)
                                {
                                        <tr>
                                            <td>
                                                @Html.ActionLink(Model.CloseLoanItems[i].DocumentNo, "LoanDetails", "Loan", null, null, null, new { documentNo = Model.CloseLoanItems[i].DocumentNo }, null)
                                                @Html.HiddenFor(m => m.CloseLoanItems[i].DocumentNo)
                                            </td>
                                            <td>
                                                @Html.ValueFor(m => m.CloseLoanItems[i].BorrowerName)
                                                @Html.HiddenFor(m => m.CloseLoanItems[i].BorrowerName)
                                            </td>
                                            <td>
                                                @Html.ValueFor(m => m.CloseLoanItems[i].AgentName)
                                                @Html.HiddenFor(m => m.CloseLoanItems[i].AgentName)
                                            </td>
                                            <td style="text-align:right">
                                                @Html.ValueFor(m => m.CloseLoanItems[i].Receivable, "{0:#,###,##0.00}")
                                                @Html.HiddenFor(m => m.CloseLoanItems[i].Receivable)
                                            </td>
                                            <td style="text-align:right">
                                                @Html.ValueFor(m => m.CloseLoanItems[i].TotalPayment, "{0:#,###,##0.00}")
                                                @Html.HiddenFor(m => m.CloseLoanItems[i].TotalPayment)
                                            </td>
                                            <td style="text-align:right">
                                                @Html.ValueFor(m => m.CloseLoanItems[i].OutstandingBalance, "{0:#,###,##0.00}")
                                                @Html.HiddenFor(m => m.CloseLoanItems[i].OutstandingBalance)
                                            </td>
                                            <td>
                                                @Html.ValueFor(m => m.CloseLoanItems[i].LoanStatus)
                                                @Html.HiddenFor(m => m.CloseLoanItems[i].LoanStatus)
                                            </td>
                                            <td>
                                                @Html.DropDownListFor(m => m.CloseLoanItems[i].RemarkID, Model.CloseLoanRemarks, new { @class = "single-line" })
                                            </td>
                                            <td style="text-align:center">
                                                @Html.CheckBoxFor(m => m.CloseLoanItems[i].IsSelected, new { @class = "check", @onchange = "checkMe()" })
                                            </td>
                                        </tr>
                                }
                                </tbody>

                            </table>
                        
                        <button type="submit" id="btnRefresh" style="display:none" name="command" value="Refresh">Refresh</button>
                        <button type="submit" id="btnSave" style="display:none"  class="btn btn-primary" name="command" value="Save">Ok</button>

                    </div>
                    <div class="modal fade" id="confirm-close" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
                        <div class="modal-dialog">
                            <div class="modal-content">

                                <div class="modal-header">
                                    <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                                    <h4 class="modal-title" id="myModalLabel">Confirmation</h4>
                                </div>

                                <div class="modal-body">
                                    <p>Are you sure you want to request to close the selected documents?</p>
                                    <p class="debug-url"></p>
                                </div>

                                <div class="modal-footer">
                                    <button type="button" class="btn btn-primary" data-dismiss="modal">No</button>
                                    <button type="button" class="btn btn-primary btn-ok" data-dismiss="modal">Yes</button>
                                </div>
                            </div>
                        </div>
                    </div>
                </fieldset>
            }
            </div>

        </div>
    </div>
</div>

@section Styles {
    @Styles.Render("~/Content/plugins/dataTables/dataTablesStyles")
    
<style>
    .divScroll {
        height: 400px;
        overflow-x: scroll;
        border: solid 1px #EBEBEB;
    }

    .divSearch {
        background-color: #F5F5F6;
        border: 1px solid #EBEBEB;
        margin-top: 5px;
    }

    .table-search {
        width: 100%;
        border: none;
    }

        .table-search td {
            margin: 10px 10px 10px 10px;
            padding: 10px 10px 10px 10px;
            vertical-align: bottom;
        }

        .table-search .tdAlignRight {
            text-align: right;
        }

        .table-search .tdFixed {
            width: 20%;
        }

            .table-search .tdFixed div {
                margin-bottom: 0px;
            }

        .table-search td .btnSearch {
            margin-bottom: 0px;
        }


        .table-search td span {
            margin-left: 7px;
        }
</style>
    
}

@section Scripts{
@Scripts.Render("~/plugins/dataTables")
<script type="text/javascript">

    $(document).ready(function () {

        $('.table-List').dataTable({
            ordering: true,
            searching: false,
            paging: false,
            scrollY: 400
        });

        $(window).keydown(function (event) {
            if (event.keyCode == 13) {
                Refresh();
                return false;
            }
        });

        $('#confirm-close').on('click', '.btn-ok', function (e) {
            document.getElementById('btnSave').click();
        });
    });

    function Refresh() {
        document.getElementById('btnRefresh').click();
    }

    function checkAll(me) {
        var val = $(me).is(':checked');

        $('.check').each(function () {
            $(this).prop('checked', val);
        });
    }

    function checkMe() {
        var allIsChecked = true;

        $('.check').each(function () {
            val = $(this).is(':checked');

            if (!val)
                allIsChecked = false;
        });

        $('#chkCheckAll').prop('checked', allIsChecked);

    }

    function SortList(orderBy) {
        var hdnOrderBy = $('#hdnOrderBy').val();
        var hdnOrder = $('#hdnOrder').val();

        if (orderBy == hdnOrderBy) {
            if (hdnOrder == 'Asc')
                $('#hdnOrder').val('Desc');
            else
                $('#hdnOrder').val('Asc');
        }
        else {
            $('#hdnOrderBy').val(orderBy);
            $('#hdnOrder').val('Asc');
        }

        Refresh();

    }

</script>

}
